package com.sohu.pickoo.frag;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class NewFragJob implements Job {

	private static Log _log = LogFactory.getLog(NewFragJob.class);

    /**
     * Quartz requires a public empty constructor so that the
     * scheduler can instantiate the class whenever it needs.
     */
    public NewFragJob() {
    }

    /**
     * <p>
     * Called by the <code>{@link org.quartz.Scheduler}</code> when a
     * <code>{@link org.quartz.Trigger}</code> fires that is associated with
     * the <code>Job</code>.
     * </p>
     * 
     * @throws JobExecutionException
     *             if there is an exception while executing the job.
     */
    public void execute(JobExecutionContext context)
        throws JobExecutionException {
    	JobDataMap dataMap = context.getJobDetail().getJobDataMap();
    	String source = (String)dataMap.get("source");
    	String target = (String)dataMap.get("target");
    	String realTarget = "";
    	try{
    		realTarget = FragService.getRealTarget(target);
    		if(realTarget==null){
    			_log.info("碎片格式不支持！");
    		}
    		FragService.createFrag(source, realTarget);   		
    	}catch(Exception e){
    		_log.error(e.toString());
    	}
        // This job simply prints out its job name and the
        // date and time that it is running
        String jobName = context.getJobDetail().getFullName();
        _log.info("NewFragJob says: " + jobName + " executing at " + new Date());
    }

}
